import time
import os
import platform

import bs4

import win32gui
import win32api
import win32con
import win32clipboard
import pyperclip

from selenium import webdriver

from worker import worker, dd ,dm , lock_wrapper
from exceptions import *

class zsyh(worker):
    """docstring for zsyh"""
    def __init__(self, backend:"后台根地址",lock:"锁",config_entity):
        super(zsyh, self).__init__(backend,lock,config_entity,old_title = "招商银行个人银行专业版")
        self.base_picture_path = "zsyh/image/"
        self.risk = float(config_entity['risk'])

    def getHwnd(self):
        self.hwnd = win32gui.FindWindow("TMainFrm",None)
        if self.hwnd == 0:
            raise GetMonitorHwndException("招商银行个人专业版窗口没找到")

    def goto_zz(self):
        if not self.wait_unit_findpic_or_timeout("zz.bmp"):
            if not self.findPicture_relative_onlybool("zz_active.bmp"):
                raise ToZZException("未能进入转账页面")
        else:
            self.findPicture_relative_and_click("zz.bmp",20,10)

    def fill_bank_info(self,name,account,money):
        print("开始填写转账信息")
        if not self.wait_unit_findpic_or_timeout("zz_active.bmp"):
            raise LockedException(self.wid,"进入跨行转账页面失败")
        self.findPicture_relative_and_click("skr.bmp",-100,10)
        time.sleep(1)
        self.c_and_p(name)
        time.sleep(1)
        dm.KeyPress(9)
        time.sleep(0.5)
        self.key_word(account)
        self.findPicture_relative_and_click("khh.bmp",150,10)
        time.sleep(1)
        self.key_word(money)
        time.sleep(1)

    def pay(self):
        self.findPicture_relative_and_click("khh.bmp",100,260)
        if not self.wait_unit_findpic_or_timeout("qkmm.bmp",sim=1):
            raise InPayException(self.wid,"付款跳转超时，尚未进入输入付款密码的页面")
        time.sleep(1)
        self.findPicture_relative_and_click("qkmm.bmp",120,10,sim=1)
        time.sleep(1)
        self.key_word(self.login_password)
        time.sleep(1)
        self.findPicture_relative_and_click("qkmm.bmp",100,60,sim=1)
        time.sleep(1)
